using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace TrovaIntruso.core
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Popup : Screen
    {
        public Rectangle surface;
        private Button close;
        public Popup(Game game)
            : base(game)
        {
            this.surface = StaticOperation.GetCenteredRectangle(95);
            Initialize();
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            int cx=surface.X+surface.Width-32 ,
                cy=surface.Y-32;
            if ((cx + 64) > StaticOperation.screen.X) cx = (int)StaticOperation.screen.X - 64;
            if (cy < 0) cy = 0; 
            close=new Button(Game,new Sprite(StaticOperation.Icons["close"],new Rectangle(cx,cy,64,64)));
            AddComponent(close);
            close.BindClick(new Button.ClickDelegate(close_Click));
        }


        private void close_Click() {
            Toggle(false);
        }

        protected override void  SelfDraw(GameTime gt)
        {
            SpriteBatch s = StaticOperation.Batch;
            s.Begin();
            s.Draw((Texture2D)StaticOperation.StaticResources["popupback"], surface, Color.White);
            s.End();   
 	        base.SelfDraw(gt);
        }
    }
}
